//
//  MainAccountSubmitBtnCell.swift
//  d11
//
//  Created by peale on 2018/9/17.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
typealias TransferSubmitBlock = () -> Void
class MainAccountSubmitBtnCell: UITableViewCell {
    var iconImgView : UIImageView?
    var titleLabel : UILabel?
    var submitBtn : UIButton?
    var transferSubmitBlock: TransferSubmitBlock?
    func callClickBlock(_ block: @escaping TransferSubmitBlock) {
        
        transferSubmitBlock = block
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        
        self.iconImgView = UIImageView.init()
        self.iconImgView?.image = imageNamed("icon_mainAccount_hint")
        self.contentView.addSubview(self.iconImgView!)
        self.iconImgView?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(12)
            make.width.equalTo(12)
            make.height.equalTo(12)
            make.top.equalTo(4+7)
        }
        
        self.titleLabel = UILabel.init()
        self.titleLabel?.text = "选择账户不可一样"
        self.titleLabel?.textColor = HexRGBAlpha(0x8E8F90, 1)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        self.titleLabel?.textAlignment = NSTextAlignment.left
        self.contentView.addSubview(self.titleLabel!)
        
        self.titleLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.iconImgView?.snp.right)!).offset(5)
            make.width.equalTo(kScreenWidth-30)
            make.height.equalTo(20)
            make.top.equalTo(7);
        }
        
       self.submitBtn  = UIButton.init(type: .custom)
        self.submitBtn?.setTitle("提交", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: kScreenWidth-20, height: 50)
        self.submitBtn?.layer.addSublayer(layerGradient)
        self.submitBtn?.layer.cornerRadius = 5;
        self.submitBtn?.layer.masksToBounds = true
        self.submitBtn?.addTarget(self, action: #selector(self.actionToTransfer), for: .touchUpInside)
        self.contentView.addSubview(self.submitBtn!)
        self.submitBtn?.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.top.equalTo((self.titleLabel?.snp.bottom)!).offset(17)
        }
    }
    
    @objc func actionToTransfer() -> Void {
        if self.transferSubmitBlock != nil {
            self.transferSubmitBlock!()
        }
    }
}
